package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.business.entity.UserGrade;
import cn.stylefeng.guns.modular.business.model.params.UserGradeParam;
import cn.stylefeng.guns.modular.business.model.result.UserGradeResult;
import cn.stylefeng.guns.modular.business.service.UserGradeService;
import cn.stylefeng.guns.sys.core.util.StringUtils;
import cn.stylefeng.guns.sys.modular.system.service.FileInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 用户等级表控制器
 *
 * @author jwj
 * @Date 2019-07-18 17:46:33
 */
@Controller
@RequestMapping("/userGrade")
public class UserGradeController extends BaseController {

    private String PREFIX = "/business/userGrade";

    @Autowired
    private FileInfoService fileInfoService;


    @Autowired
    private UserGradeService userGradeService;

    /**
     * 跳转到主页面
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/userGrade.html";
    }

    /**
     * 新增页面
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/userGrade_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/userGrade_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(UserGradeParam userGradeParam) {
        this.userGradeService.add(userGradeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(UserGradeParam userGradeParam) {
        this.userGradeService.update(userGradeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(UserGradeParam userGradeParam) {
        this.userGradeService.delete(userGradeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(UserGradeParam userGradeParam) {
        UserGrade detail = this.userGradeService.getById(userGradeParam.getGradeId());
        UserGradeResult result = new UserGradeResult();
        ToolUtil.copyProperties(detail, result);
        return ResponseData.success(result);
    }

    /**
     * 查询列表
     *
     * @author jwj
     * @Date 2019-07-18
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UserGradeParam userGradeParam) {
        return this.userGradeService.findPageBySpec(userGradeParam);
    }

}


